package com.dmbjz.profilesdemo;

import com.dmbjz.profilesdemo.bean.*;
import com.dmbjz.profilesdemo.entity.Shop;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;


/*
    容器中的组件都可以被 @Profile标记
        1、如果组件不标注@Profile，任意环境都生效
        2、标注 @Profile("xx")，只有对应的环境才生效
        3、默认环境 default
     激活方式：
        可通过配置文件方式激活：spring.profiles.active=dev,test
        启动项目时通过命令激活：java -jar xxx.jar --spring.profiles.active=dev,test
 */
@SpringBootApplication
@Slf4j
public class ProfilesDemoApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext iocContext = SpringApplication.run(ProfilesDemoApplication.class, args);

        //获取配置文件绑定数据

        try {
            Cat cat = iocContext.getBean(Cat.class);
            log.info("cat信息：{}", cat);
        } catch (BeansException e) {
            log.error("cat信息输出异常，原因：", e);
        }

        try {
            Dog dog = iocContext.getBean(Dog.class);
            log.info("dog信息：{}", dog);
        } catch (BeansException e) {
            log.error("dog信息输出异常，原因：", e);
        }

        try {
            Person person = iocContext.getBean(Person.class);
            log.info("person信息：{}", person);
        } catch (BeansException e) {
            log.error("person信息输出异常，原因：", e);
        }

        try {
            Phone phone = iocContext.getBean(Phone.class);
            log.info("phone信息：{}", phone);
        } catch (BeansException e) {
            log.error("phone信息输出异常，原因：", e);
        }

        try {
            Shop shop = iocContext.getBean(Shop.class);
            log.info("shop信息：{}", shop);
        } catch (BeansException e) {
            log.error("shop信息输出异常，原因：", e);
        }

    }

}
